<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>4-</title>
    <style>
        div {
            width: 600px;
            margin: 100px auto;
        }

        .message {
            display: inline-block;
            font-size: 12px;
            color: #999;
            padding-left: 20px;
        }

        .wrong {
            color: red;
        }

        .right {
            color: green;
        }
    </style>
</head>

<body>
    <div class="register">
        <input class="ipt" type="password" name="" id="">
        <p class="message">请输入6~16位密码</p>
    </div>

    <script>
        let ipt = document.querySelector('.ipt');
        let message = document.querySelector('.message');
        // 2. 注册事件，失去焦点；2021-9-6 02:39:28
        ipt.onblur = function () {
            if (this.value.length < 6) {
                // console.log('错误，密码小羽6位');
                message.className += ' wrong';
                message.innerHTML = '错误，密码小羽6位';
            } else if (this.value.length > 16) {
                // console.log('错误，密码大于16位');
                message.className += ' wrong';
                message.innerHTML = '错误，密码大于16位';
            } else {
                message.className += ' right';
                message.innerHTML = '没问题';
            }
        }
    </script>
</body>

</html>